package cn.com.aiton.common.utils;

import cn.com.aiton.common.model.ServiceResult;
import cn.com.aiton.common.model.extend.AitonExtendCountDownDomain;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.List;

public class JsonToCountDownListUtil {
    private static final ObjectMapper objectMapper = new ObjectMapper();
    private static final Logger LOG =
            LoggerFactory.getLogger(JsonToGreenConflictListUtil.class);
    public static ServiceResult<List<AitonExtendCountDownDomain>> json2CountDownList(String json){
        ServiceResult<List<AitonExtendCountDownDomain>> result = new ServiceResult<>();
        List<AitonExtendCountDownDomain> listll = null;
        try {
            listll = objectMapper.readValue(json, new TypeReference<List<AitonExtendCountDownDomain>>(){});
        } catch (IOException e) {
            LOG.error(e.getMessage());
            result.setObject(null);
            result.setSuccess(false);
            result.setMessage("JSON数据转换成CountDown失败");
        }
        result.setObject(listll);
        result.setSuccess(true);
        result.setMessage("JSON数据转换成CountDown成功");
        return result;
    }
}
